#ifndef MODEL_FRAME_H

//--------------------------------------------------------
//		DEFINITIONS
//--------------------------------------------------------
#define MODEL_FRAME_H

//--------------------------------------------------------
//		INCLUDES
//--------------------------------------------------------
#include <vector>
#include <QTimer>
#include <OpenMesh/Core/Geometry/VectorT.hh>
#include <OpenMesh/Core/IO/MeshIO.hh>
#include <OpenMesh/Core/IO/Options.hh>
#include <OpenMesh/Core/Mesh/PolyMesh_ArrayKernelT.hh>
#include "Transformer.h"
#include "MeshSpecifics.h"

using namespace OpenMesh;

//--------------------------------------------------------
//		CLASS: ModelFrame
//--------------------------------------------------------
class ModelFrame : public QObject
{
	Q_OBJECT

public:

	enum Selectable {NONE, COARSE, RECONNECTED, ANIMATED};

	//Construction/destruction
	ModelFrame()
	{ 
		this->signalConnected	= false;
		this->numSubdivs		= 0;
		this->selectable		= NONE;
		this->coarse			= new PolyMesh();
		this->reconnected		= NULL;
		this->subdivided		= NULL;
		this->important			= NULL;
	}
	~ModelFrame()
	{
		if( coarse )
			delete coarse;
		if( reconnected )
			delete reconnected;
		if( subdivided )
			delete subdivided;
		if( important )
			delete important;
	}

	void setActive( Selectable mode )
	{
		if( mode == RECONNECTED )
			active = reconnected;
		if( mode == ANIMATED )
			active = &animated;
	}


	void deleteImportance()
	{
		if( important )
			delete important;
		important = NULL;
	}

	ModelFrame* getCopy()
	{
		ModelFrame* copy;

		copy				= new ModelFrame();
		copy->loadOptions	= this->loadOptions;
		copy->t				= this->t;
		copy->coarse		= this->coarse == NULL? NULL : new PolyMesh(*this->coarse);
		copy->subdivided	= this->subdivided == NULL? NULL : new PolyMesh(*this->subdivided);
		copy->reconnected	= this->reconnected == NULL? NULL : new PolyMesh(*this->reconnected);
		copy->animated		= this->animated;

		if (active == coarse) { copy->active = copy->coarse; }
		if (active == reconnected) {copy->active = copy->reconnected; }
		if (active == &animated) {copy->active = &copy->animated; }

		return copy;
	};


	PolyMesh* getSelectableMesh()
	{
		if (selectable == COARSE) {return coarse;}
		if (selectable == RECONNECTED) {return reconnected;}
		//if (selectable == ANIMATED) {return &animated;}
		return NULL;
	};

	PolyMesh* getImportanceMesh()
	{
		return this->important;
	};

	void setImportanceMesh(PolyMesh* mesh)
	{
		this->important = mesh;
		emit importanceChanged();
	};

	//Class attributes
	bool			signalConnected;	// flag: is importance changed stignal connected
	int				numSubdivs;			// the number of times this frame was subdivided
	int				selectable;			// pointer to the mesh that can be selected
	IO::Options		loadOptions;		// options from when the mesh was first loaded
	Transformer		t;					// tranformations on model frame
	PolyMesh*		coarse;				// the original (coarse) mesh
	PolyMesh*		reconnected;		// reconnected, but weights not applied mesh
	PolyMesh*		subdivided;			// completely subdivided mesh
	PolyMesh		animated;			// intermediate mesh for animation
	PolyMesh*		active;

signals:

	void importanceChanged();
	void setAnimateSliderValue(int);

private:

	PolyMesh*	 important;		// subset of coarse mesh showing important connections
};

#endif